/*###########################################################
# © 2013-2016 Daniel 'grindhold' Brendle
#
# This file is part of Nostril.
#
# Nostril is free software: you can redistribute it and/or 
# modify it under the terms of the GNU Affero General Public License 
# as published by the Free Software Foundation, either 
# version 3 of the License, or (at your option) any later 
# version.
#
# Nostril is distributed in the hope that it will be 
# useful, but WITHOUT ANY WARRANTY; without even the implied 
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
# PURPOSE. See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public 
# License along with Nostril. 
# If not, see http://www.gnu.org/licenses/.
###########################################################*/

using Gtk;
using Soup;

namespace nostril {
    namespace gui {
        /**
         * Baseclass for everything that renders a nostril.data.Object
         * Such an object is passed to the Constructor of the DataRenderer
         * by the Class that inherits it and stored as data source
         * The inheriting class must implement the render()-method.
         */
        public abstract class DataRenderer {
            private nostril.data.Object _data_source = null;

            /**
             * Stores the data source
             */
            protected nostril.data.Object data_source {get { return this._data_source;}}

            /**
             * This method is to be implemented in inheriting classes.
             * It will be called everytime the datasource changes and is
             * responsible for changing the GUI-widget's texts/graphics to
             * match the newly set content of the represented datasource
             */
            public abstract void render();

            /**
             * This constructor takes a nostril.data.Object and stores it.
             * This will be the object that this DataRenderer gets it data from.
             * It must be called via base() in the inheriting Constructor
             */
            public DataRenderer(nostril.data.Object source){
                this._data_source = source;
                this._data_source.set_renderer(this);
            }

            /**
             * Destructor - Unregisters this Renderer from the Object it renders
             */
            ~DataRenderer(){
                this._data_source.unset_renderer(this);
            }
        }
    }
}